package com.app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

/**
 * View 和 SurfaceView 组合使用 动画效果
 * 背景是SurfaceView
 * 前景动画是View
 * @author Administrator
 *
 */
public class AniActivity extends Activity {
	private static String		logName	= "AniActivity";
	public static AniActivity	instance;
	public static Context		content;

	public AniActivity() {
		Log.e(logName, "构造");
	}

	private AniView			aniView		= null;
	private AniSurfaceView	aniSView	= null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.e(logName, "onCreate");
		instance = this;
		content = this;
		//		setContentView(R.layout.main);
		initView();
		this.setContentView(layout);
	}

	private RelativeLayout	rlayout	= null;
	private LinearLayout	layout	= null;

	private void initView() {
		layout = new LinearLayout(this);
		rlayout = new RelativeLayout(this);
		layout.addView(rlayout);
		//		layout.setOrientation(LinearLayout.VERTICAL);
		//		layout.setBackgroundColor(Color.BLACK);
		aniView = new AniView(this);
		aniSView = new AniSurfaceView(this);
		//注意先后顺序
		rlayout.addView(aniSView);
		rlayout.addView(aniView);
		//初始化化焦点所属，如果view里有设置，则不能放在onCreate里，那时侯设置会被冲掉?
		//反正设置不会像预期的那么好（对于多View时）
		//起码要间隔一个函数，在onStart()里设置
		aniView.setFocusable(true);
		aniView.setFocusableInTouchMode(true);
	}

	protected void onStart() {
		Log.e(logName, "onStart");
		super.onStart();
	}

	protected void onRestart() {
		Log.e(logName, "onRestart");
		super.onRestart();
	}

	protected void onResume() {
		Log.e(logName, "onResume");
		super.onResume();
	}

	protected void onPause() {
		Log.e(logName, "onPause");
		super.onPause();
	}

	protected void onStop() {
		Log.e(logName, "onStop");
		super.onStop();
	}

	protected void onDestroy() {
		Log.e(logName, "onDestroy");
		super.onDestroy();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		Log.i(logName, "KEY=" + keyCode);
		return super.onKeyDown(keyCode, event);
	}
}
